import { ca } from "element-plus/es/locales.mjs";
import service from "../request.js";
import { ElMessage } from "element-plus";

// 获取协会信息
export function getAssociation(){
    return service({
        method:"get",
        url:'/association',
    })
}

// 修改协会信息
export function updateAssociation(association){
    return service({
        method:"put",
        url:'/association',
        data:association
    })
}

/*
// 文件上传
export function uploadFile(file){
    return service({
        method:"post",
        url:'/file/upload',
        data:file
    })
}*/


// 文件下载
export async function downloadFile(path){
    try{
    let blob = await service({
        method:'get',
        url:`/common/download/${path}`,
        responseType:'blob'
    })
    // 模拟点击下载
    // 获取文件名
    let [, filename] = path.split("_")
    // 创建临时下载链接并触发下载
    const url = window.URL.createObjectURL(blob)
    const link = document.createElement('a')
    link.href = url
    link.setAttribute('download',filename)
    document.body.appendChild(link)
    link.click()
    link.remove()
    window.URL.revokeObjectURL(url)
 }catch(e){
    ElMessage({message:'下载失败',type:'warning',})
 }
}